package com.dcbeida.activity.msg;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.KeyEvent;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.dcbeida.R;
import com.dcbeida.activity.BaseActivity;
import com.dcbeida.bean.MsgBean;
import com.dcbeida.bean.MsgDetailBean;
import com.dcbeida.bean.MsgFeedBack;
import com.just.agentweb.AgentWeb;

import butterknife.Bind;
import butterknife.OnClick;


/**
 * 帮助手册
 */
public class MessageDetailActivity extends BaseActivity implements MsgDetailContract.View {


    @Bind(R.id.img_back)
    ImageView imgBack;
    @Bind(R.id.tv_title)
    TextView tvTitle;
    @Bind(R.id.tv_msg_title)
    TextView tvMsgTitle;
    @Bind(R.id.tv_about)
    TextView tvAbout;
    @Bind(R.id.tv_content)
    TextView tvContent;
    @Bind(R.id.tv_confim)
    TextView tvConfim;
    @Bind(R.id.et_feed_back)
    EditText etFeedBack;
    @Bind(R.id.lin_noHas)
    LinearLayout linNoHas;
    @Bind(R.id.lin_has)
    LinearLayout linHas;
    @Bind(R.id.tv_feed_back_name)
    TextView tvFeedBackName;
    @Bind(R.id.tv_feed_back)
    TextView tvFeedBack;
    @Bind(R.id.tv_from)
    TextView tvFrom;




    private MsgBean currentMsg;

    private MsgDetailPresenter msgDetailPresenter;



    @Override
    protected int getLayoutResId() {
        return R.layout.activity_message_detail;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initData();

    }

    private void initData(){
        msgDetailPresenter = new MsgDetailPresenter(this,this);
        tvTitle.setText("通知详情");
        Bundle bundle = getIntent().getExtras();
        if (null != bundle) {
            currentMsg = (MsgBean) bundle.getSerializable("msgbean");
            msgDetailPresenter.getDetail((int) currentMsg.getMessageid());
        }


    }

    @OnClick({R.id.img_back,R.id.tv_confim})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.img_back:
                finish();
                break;
            case R.id.tv_confim:
                String feedBack = etFeedBack.getText().toString();
                if(TextUtils.isEmpty(feedBack)){
                    showTip("请填写反馈信息");
                    return;
                }
                msgDetailPresenter.confirmFeedBack(feedBack, (int) currentMsg.getMessageid());
                break;
        }
    }


    @Override
    public void showTip(String msg) {

    }

    @Override
    public void showDetail(MsgDetailBean msgDetailBean) {
        tvMsgTitle.setText(msgDetailBean.getTitle());
        String about=msgDetailBean.getAuthor()+"\t\t"+msgDetailBean.getCreatetime()+"\t\t"+"发布";
        tvAbout.setText(about);
        tvContent.setText(msgDetailBean.getContent());
        if(msgDetailBean.getFeedback() != null){
            linNoHas.setVisibility(View.GONE);
            linHas.setVisibility(View.VISIBLE);
            MsgFeedBack msgFeedBack = msgDetailBean.getFeedback();
            String fbName=msgFeedBack.getTruename()+"\t\t"+msgFeedBack.getCreatetime()+"\t\t"+"反馈:";
            tvFeedBackName.setText(fbName);
            tvFeedBack.setText(msgFeedBack.getContent());
            String from ="来自:"+"\t"+msgFeedBack.getShopname();
            tvFrom.setText(from);
        }else {
            linNoHas.setVisibility(View.VISIBLE);
            linHas.setVisibility(View.GONE);
        }
    }

    @Override
    public void confirmSuccess() {
        showTip("消息反馈成功");
        finish();
    }

    @Override
    public void setPresenter(MsgDetailContract.Present presenter) {

    }
}
